<%@ page import="java.sql.ResultSet" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/common/config.jsp" %>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<html>
<head>
</head>
<body>
<center>
    <form action="query.jsp" method="post" id="form">
        <input type="hidden" name="pageIndex" id="pageIndex" value="1">
        请输入学号：<input type="text" name="sno" value="${sno}">
        请输入姓名:<input type="text" name="name" value="${name}">
        请选择班级：<select name="clazz">
        <option value="">全部</option>
        <option value="18电子商务技术1班" ${clazz=='18电子商务技术1班'?'selected':''}>18电子商务技术1班</option>
        <option value="18电子商务技术2班" ${clazz=='18电子商务技术2班'?'selected':''}>18电子商务技术2班</option>
        <option value="18计算机应用技术（数据应用）" ${clazz=='18计算机应用技术（数据应用）'?'selected':''}>18计算机应用技术（数据应用）</option>
    </select>
        <input type="submit" value="查询">
    </form>
    <input type="button" value="添加" onclick="add();">
    <input type="button" value="删除" onclick="del();">
    <table border="1px" width="930px">
        <tr>
            <td width="30px">
                <input type="checkbox" id="checkAll" onchange="checkAll();">全选
            </td>
            <td width="150px">学号</td>
            <td width="150px">姓名</td>
            <td width="300px">班级</td>
            <td width="200px">操作</td>
        </tr>

        <c:forEach items="${list}" var="student">
            <tr>
                <td width="30px">
                    <input type="checkbox" name="checkbox_id" value="${student.id}">
                </td>
                <td width="150px">${student.sno}</td>
                <td width="150px">${student.name}</td>
                <td width="300px">${student.clazz}</td>
                <td width="200px">
                    <a href="#">查看</a> | <a href="#">修改</a> | <a href="#">删除</a>
                </td>
            </tr>
        </c:forEach>

        <tr align="center">
            <td colspan="5">
            </td>
        </tr>

    </table>
</center>
<script type="application/javascript">

    var form = document.getElementById("form");
    var pageIndex = document.getElementById("pageIndex");


    function checkAll() {
        var checkAll = document.getElementById("checkAll");
        var checkAllids = document.getElementsByName("checkbox_id");
        for (var i = 0; i < checkAllids.length; i++) {
            checkAllids[i].checked = checkAll.checked;
        }
    }

    function del(id) {
        if (id) {
            if (confirm("你是否要删除学号为" + id + "的同学吗？")) {
                window.location = "saveOrUpdate.jsp?action=delete&id=" + id;
            } else {
                alert("你取消了删除学号为" + id + "的同学");
            }
        } else {
            var checkAllids = document.getElementsByName("checkbox_id");
            var delIds = '';
            for (var i = 0; i < checkAllids.length; i++) {
                if (checkAllids[i].checked) {
                    delIds += checkAllids[i].value + ',';
                }
            }
            if (delIds) {
                if (confirm("你是否要删除选中的同学吗？")) {
                    window.location = "saveOrUpdate.jsp?action=delete&id=" + delIds;
                } else {
                    alert("你取消了删除学号为" + id + "的同学");
                }
            } else {
                alert("请至少选择一个要删除的学生");
            }


        }
    }

    function add() {
        window.location = "edit.jsp?action=add";
    }

    function pageQuery(page) {
        pageIndex.value = page;
        form.submit();
    }

</script>


</body>
</html>

